Index | < Browse | Browse >
LETTERfmodULETTER
Calculates the modulus for floating-point divisions.
Overview
#include <math.h>
x = fmod(y, z);
double x, y, z;
Portability
ANSI
Description
This function calculates the floating-point remainder for y/z (similar to
x = y % z, if the % modulus operator were defined for floating-point
operators). Don't mix up this function with modf.
Returns
"fmod" returns the value of "y", if "z" does not equal "z". Otherwise a value
smaller than "z" and with the same sign as "y" is returned.
See also
modf
Example
#include <stdio.h>
#include <math.h>
void main(void)
{
double r;
r = fmod(5.2, 1.5); // r contains 1.2
printf("fmod(5.7, 1.5) = %lf\n", r);
}